package com.joe.test_mybatis_plus.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.concurrent.TimeUnit;

/**
 * @author Joe
 * @description redis测试key过期
 * @time 2023/5/29 10:42
 **/
@Slf4j
@RestController
@RequestMapping("/redis")
@Api(tags = "redis测试")
public class RedisController {
    @Autowired
    private RedisTemplate redisTemplate;

    @PostMapping("/set")
    @ApiOperation(value = "加入测试值")
    public void set(@RequestBody List<String> keys) {
        for (String key : keys) {
            redisTemplate.opsForValue().set(key, "100", 60, TimeUnit.SECONDS);
            log.info("向redis里存入数据key={},设置缓存时间{}", key, 60);
        }
    }
}
